package com.hudson.common.domain.request;

import java.util.Objects;

/**
 * @Author: 渔小鲤
 * @DateTime: 2025/7/7 0:01
 **/
public class DefaultSendMessageReq<T> {

    private final String type;
    private final String messageId;
    private final String topic;

    private final int queueId;
    private final T jsonObj;

    // 私有构造函数，由 Builder 调用
    private DefaultSendMessageReq(Builder<T> builder) {
        this.type = builder.type;
        this.messageId = builder.messageId;
        this.topic = builder.topic;
        this.jsonObj = builder.jsonObj;
        this.queueId = builder.queueId;
    }

    // 默认构造函数
    public DefaultSendMessageReq(String type, String messageId, String topic, int queueId, T jsonObj) {
        this.type = type;
        this.messageId = messageId;
        this.topic = topic;
        this.queueId = queueId;
        this.jsonObj = jsonObj;
    }


    public String getMessageId() {
        return messageId;
    }

    public String getTopic() {
        return topic;
    }

    public T getJsonObj() {
        return jsonObj;
    }

    public String getType() {
        return type;
    }

    public int getQueueId() {
        return queueId;
    }

    // Builder 内部类
    public static class Builder<T> {
        private String type;
        private String messageId;
        private String topic;
        private int queueId;
        private T jsonObj;

        public Builder<T> type(String type) {
            this.type = type;
            return this;
        }

        public Builder<T> messageId(String messageId) {
            this.messageId = messageId;
            return this;
        }

        public Builder<T> topic(String topic) {
            this.topic = topic;
            return this;
        }

        public Builder<T> queueId(int queueId) {
            this.queueId = queueId;
            return this;
        }

        public Builder<T> jsonObj(T jsonObj) {
            this.jsonObj = jsonObj;
            return this;
        }

        public DefaultSendMessageReq<T> build() {
            return new DefaultSendMessageReq<T>(this);
        }
    }

    public static <T> Builder<T> builder() {
        return new Builder<T>();
    }

    public boolean isEmpty(){
        return Objects.isNull(jsonObj);
    }

    @Override
    public String toString() {
        return "DefaultSendMessage{" +
                "type='" + type + '\'' +
                ", messageId='" + messageId + '\'' +
                ", topic='" + topic + '\'' +
                ", jsonObj=" + jsonObj +
                '}';
    }
}
